{% extends "course/nav.html" %}
{% block title %}课程详情{% endblock %}
{% block content %}
    {% load static %}
    <link href="{% static 'css/list.css' %}" rel="stylesheet">
    <h3>课程详情<input class="button right-button" type="button" value="返回主页"
                   onclick='window.open("{% url 'course' 'teacher'%}")'/></h3>
    <table class="item-list detail-list">
        <thead>
            <tr>
                <th>课程编号</th>
                <th>名称</th>
                <th>学分</th>
                <th>当前人数/总人数</th>
                <th>年份</th>
                <th>学期</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>{{ course.id }}</td>
                <td>{{ course.name }}</td>
                <td>{{ course.credit }}</td>
                <td>{{ course.get_current_count }}/{{ course.max_number }}</td>
                <td>{{ course.year }}</td>
                <td>{{ course.get_semester_display }}</td>
            </tr>
        </tbody>
    </table>

    <h3>上课时间<input class="button right-button" type="button" value="添加时间表" onclick='window.open("{% url 'create_schedule' course.id%}")'/></h3>
    <table class="item-list schedule-list">
        <thead>
            <tr>
                <th class="schedule-no">编号</th>
                <th class="schedule-no">详情</th>
                <th class="schedule-no">操作</th>
            </tr>
        </thead>
        <tbody>
            {% for schedule in schedules %}
            <tr>
                <td>{{ schedule.id }}</td>
                <td>{{ schedule }}</td>
                <td>
                    <input class="button" type="button" value="删除"
                           onclick='window.open("{% url 'delete_schedule' schedule.id%}?course_id={{ course.id }}")'/>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    <h3>学生列表
        {% if course.status == 4 %}
            <input class="button right-button" type="button" value="给分完成" onclick='location.href="{% url 'handle_course' course.id 4%}"' />
        {% endif %}
    </h3>
    <table class="item-list student-list">
        <thead>
            <tr>
                <th class="student-no">学生学号</th>
                <th class="student-name">学生姓名</th>
                <th class="student-email">学生邮箱</th>
                <th class="student-score">得分</th>
                <th class="student-comments">评价</th>
                <th class="operation">操作</th>
            </tr>
        </thead>
        <tbody>
            {% for cs in course_students %}
            <tr>
                <td>{{ cs.student.get_id}}</td>
                <td>{{ cs.student.name }}</td>
                <td>{{ cs.student.email }}</td>
                <td>
                    {% if cs.scores == None %}-{% endif %}
                    {% if cs.scores != None %}{{ cs.scores }}{% endif %}
                </td>
                <td>
                    {% if cs.scores == None %}-{% endif %}
                    {% if cs.scores != None %}{{ cs.comments }}{% endif %}
                </td>
                <td class="operation">
                    {% if course.status == 4 %}
                        {% if cs.scores == None %}
                            <input class="button right-button" type="button" value="给分"
                               onclick='location.href="{% url 'score' cs.id%}"' />
                        {% else %}
                            <input class="button right-button" type="button" value="修改成绩"
                               onclick='location.href="{% url 'score' cs.id%}?update=1"' />
                        {% endif %}
                    {% else %}
                        -
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    {% if course.status == 5 %}
    <h3>学生评价</h3>
    <table class="item-list student-list">
        <thead>
            <tr>
                <th class="student-score">学生评分</th>
                <th class="student-comments">学生评价</th>
            </tr>
        </thead>
        <tbody>
            {% for cs in sorted_course_students %}
            {% if cs.rating != None %}
            <tr>
                <td>{{ cs.rating }}</td>
                <td>{{ cs.assessment }}</td>
            </tr>
            {% endif %}
            {% endfor %}
        </tbody>
    </table>
    {% endif %}
{% endblock %}